package cn.qyl.joha.dao.Impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import cn.qyl.joha.common.PageModel;
import cn.qyl.joha.dao.BaseDao;
import cn.qyl.joha.dao.TimeDao;
import cn.qyl.joha.dto.Timlimited;
import cn.qyl.joha.mapper.TimeMapper;


/**
 * 限时抢购商品数据访问层接口实现方法类
 * @author Administrator
 *
 */
public class TimeDaoImpl extends BaseDao implements TimeDao {
	
	
	//限时抢购商品总记录数数据访问层接口实现方法
	@Override
	public int getCountByTime(Timlimited time) {
		
		SqlSession sqlSession = getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		int count = timeMapper.getCountByTime(time);
		
		closeSqlSession();
		
		return count;
	}

	
	//限时抢购商品分页数据访问层接口实现方法
	@Override
	public List<Timlimited> getTime(Timlimited time,PageModel pageModel) {
		
		SqlSession sqlSession = getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		List<Timlimited> times = timeMapper.getTime(time,pageModel);
		
		closeSqlSession();
		
		return times;
	}
	
	//删除限时抢购商品数据访问层接口实现方法
	@Override
	public int delTimeById(int id) {
		
		SqlSession sqlSession = getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		int count = timeMapper.delTimeById(id);
		
		sqlSession.commit();
		
		closeSqlSession();
		
		return count;
	}
	//批量限时抢购商品数据访问层接口实现方法
	@Override
	public int delTimeByTids(int[] tids) {
		
		SqlSession sqlSession = getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		int count =timeMapper.delTimeByTids(tids);
		
		sqlSession.commit();
		
		closeSqlSession();
		
		return count;
	}

	//新增时抢购商品数据访问层接口实现方法
	@Override
	public void addTime(Timlimited time) {
		
		SqlSession sqlSession = getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		timeMapper.addTime(time);
		
		sqlSession.commit();
		
		closeSqlSession();
		
	}

	//获取抢购商品数据列表访问层接口实现方法
	@Override
	public List<Map<String,String>> getTimeList() {
		
		SqlSession sqlSession = getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		List<Map<String,String>> map = timeMapper.getTimeList();
		
		closeSqlSession();
		
		return map;
	}

	
	//根据id获取限时抢购商品数据访问层接口实现方法
	@Override
	public Timlimited updateTimeById(int id) {
		
		SqlSession sqlSession = getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		Timlimited time = timeMapper.updateTimeById(id);
		
		closeSqlSession();
		
		return time;
	}

	
	//修改限时抢购商品数据访问层接口实现方法
	@Override
	public int updateTime(Timlimited time) {
		
		SqlSession sqlSession = getSqlSession();
		
		TimeMapper timeMapper = sqlSession.getMapper(TimeMapper.class);
		
		int count = timeMapper.updateTime(time);
		
		sqlSession.commit();
		
		closeSqlSession();
		
		return count;
	}

}
